<?php 
class GoodsViewModel extends ViewModel{
	//操作表
	public $table='goods';
	//
	public function __init(){

	}

	public $view=array(
		'goods'=>array('_type'=>'INNER'),
		'category'=>array('_on'=>'goods.category_cid=category.cid')
	);

	public function getOne($gid=0){
		$gid=$gid?intval($gid):Q('gid',0,'intval');
		//商品不存在
		if(!$gid){
			$this->error='商品不存在';
			return false;
		}
		$goods=M('goods')->join('__goods__ g JOIN __category__ c ON g.category_cid=c.cid JOIN __goods_data__ gd on g.gid=gd.goods_gid')->find($gid);
		// p($goods);exit;
		if($goods){
			//图片添加域名
			if($goods['goods_img']){
				$goods['goods_img']=__ROOT__.'/'.$goods['goods_img'];
			}
			if($goods['goods_thumb']){
				$goods['goods_thumb']=__ROOT__.'/'.$goods['goods_thumb'];
			}
		}
		return $goods;
	}

	


}


?>